//
//  WithBackBtnViewController.m
//  YouthOlympic2014
//
//  Created by xiangpaopao on 14-7-1.
//  Copyright (c) 2014年 mitian. All rights reserved.
//

#import "WithBackBtnViewController.h"
#import "NSString+FontAwesome.h"
#import "UIViewController+MMDrawerController.h"

@interface WithBackBtnViewController ()

@property (nonatomic, strong)UIViewController *leftCtrl;
@property (nonatomic, strong)UIViewController *rightCtrl;

@end

@implementation WithBackBtnViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupLeftButton];
    self.leftCtrl = self.mm_drawerController.leftDrawerViewController;
    self.rightCtrl = self.mm_drawerController.rightDrawerViewController;
    
    self.mm_drawerController.leftDrawerViewController = nil;
    self.mm_drawerController.rightDrawerViewController = nil;
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}


-(void)setupLeftButton{
    UIButton* leftButton= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [leftButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [leftButton.titleLabel setFont:[UIFont fontWithName:kFontAwesomeFamilyName size:26]];
    [leftButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-angle-left"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(leftButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftDrawerButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    
    [self.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
}


-(void)leftButtonPress:(id)sender{
    //
    [self.navigationController popViewControllerAnimated:YES];
    self.mm_drawerController.leftDrawerViewController = self.leftCtrl;
    self.mm_drawerController.rightDrawerViewController = self.rightCtrl;
}


@end
